\[Outcome = b_0 + b_1\times Predictor_1 + \varepsilon\]
\[F =\frac{what\ the model\ can\ explain}{what\ the\ model\ cannot\ explain }=\frac{signal}{noise}\]
We want signal to be as big as possible
We want noise to be as small as possible
A ratio of variance explained relative to varience unexplained
Ratio > 1 means our model can explain more than it cannot explain
Associated p-value of how likely we are to find a F-statistic as large as the observed if the null hypothesis is true
\[\begin{aligned}Outcome &= Model + Error\\ Y&=b_0 + b_1\times Predictor_1 + \varepsilon\\ &=b_0 + b_1\times Predictor_1 + b_2\times Predictor_2 + \varepsilon\end{aligned}\]
The outcome:
Predictor 1:
Predictor 2:
\[happiness\ =\ b_0 + b_1\times puppies\ +\ b_2\times fluffy + \varepsilon\]
## fit the linear model
eg4.mod1.lm <- lm(happiness ~ puppies, data = eg4.data.tib)
## get fit statistics
broom::glance(eg4.mod1.lm)
# A tibble: 1 x 11
r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC
<dbl> <dbl> <dbl> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
1 0.744 0.730 1.63 52.4 9.90e-7 2 -37.1 80.2 83.2
# ... with 2 more variables: deviance <dbl>, df.residual <int>
eg4.mod1.lm <- lm(happiness ~ puppies, data = eg4.data.tib)
broom::glance(eg4.mod1.lm)
# A tibble: 1 x 11
r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC
<dbl> <dbl> <dbl> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
1 0.744 0.730 1.63 52.4 9.90e-7 2 -37.1 80.2 83.2
# ... with 2 more variables: deviance <dbl>, df.residual <int>Predictor 3:
Model 1:
\[\begin{aligned}happiness\ = &\ b_0\ +\\&\ b_1\times puppies\ +\\ &\ b_2\times fluffy + \varepsilon\end{aligned}\]
Model 2:
\[\begin{aligned}happiness\ = &\ b_0\ +\\&\ b_1\times puppies\ +\\ &\ b_2\times fluffy\ +\\ &\ b_3\times dirt + \varepsilon\end{aligned}\]
## Model 1
eg4.mod1.lm <- lm(happiness ~ puppies, data = eg4.data.tib)
## Model 2
eg4.mod2.lm <- lm(happiness ~ puppies + dirt + wet, data = eg4.data.tib)Model 1:
broom::glance(eg4.mod1.lm)
# A tibble: 1 x 11
r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC
<dbl> <dbl> <dbl> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
1 0.744 0.730 1.63 52.4 9.90e-7 2 -37.1 80.2 83.2
# ... with 2 more variables: deviance <dbl>, df.residual <int>
Model 2:
broom::glance(eg4.mod2.lm)
# A tibble: 1 x 11
r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC
<dbl> <dbl> <dbl> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
1 0.971 0.965 0.583 178. 1.68e-12 4 -15.3 40.7 45.7
# ... with 2 more variables: deviance <dbl>, df.residual <int>eg4.anova <- anova(eg4.mod1.lm,eg4.mod2.lm) %>% broom::tidy()
eg4.anova
# A tibble: 2 x 6
res.df rss df sumsq statistic p.value
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 18 47.8 NA NA NA NA
2 16 5.43 2 42.4 62.4 0.0000000278broom::tidy(eg4.mod2.lm, conf.int = TRUE)
# A tibble: 4 x 7
term estimate std.error statistic p.value conf.low conf.high
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 3.74 0.438 8.55 2.33e- 7 2.81 4.67
2 puppies 0.995 0.0566 17.6 7.01e-12 0.875 1.11
3 dirt 0.181 0.0744 2.43 2.75e- 2 0.0228 0.338
4 wet -0.796 0.0726 -11.0 7.59e- 9 -0.950 -0.642broom::tidy(eg4.mod2.lm, conf.int = TRUE)
# A tibble: 4 x 7
term estimate std.error statistic p.value conf.low conf.high
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 3.74 0.438 8.55 2.33e- 7 2.81 4.67
2 puppies 0.995 0.0566 17.6 7.01e-12 0.875 1.11
3 dirt 0.181 0.0744 2.43 2.75e- 2 0.0228 0.338
4 wet -0.796 0.0726 -11.0 7.59e- 9 -0.950 -0.642broom::tidy(eg4.mod2.lm, conf.int = TRUE)
# A tibble: 4 x 7
term estimate std.error statistic p.value conf.low conf.high
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 3.74 0.438 8.55 2.33e- 7 2.81 4.67
2 puppies 0.995 0.0566 17.6 7.01e-12 0.875 1.11
3 dirt 0.181 0.0744 2.43 2.75e- 2 0.0228 0.338
4 wet -0.796 0.0726 -11.0 7.59e- 9 -0.950 -0.642lm.beta::lm.beta(eg4.mod2.lm)
Call:
lm(formula = happiness ~ puppies + dirt + wet, data = eg4.data.tib)
Standardized Coefficients::
(Intercept) puppies dirt wet
0.0000000 0.8326795 0.1149789 -0.4675909 lm.beta::lm.beta(eg4.mod2.lm)
Call:
lm(formula = happiness ~ puppies + dirt + wet, data = eg4.data.tib)
Standardized Coefficients::
(Intercept) puppies dirt wet
0.0000000 0.8326795 0.1149789 -0.4675909 lm.beta::lm.beta(eg4.mod2.lm)
Call:
lm(formula = happiness ~ puppies + dirt + wet, data = eg4.data.tib)
Standardized Coefficients::
(Intercept) puppies dirt wet
0.0000000 0.8326795 0.1149789 -0.4675909 Don’t forget to save this page on your computer, otherwise you will lose all notes!